import 'package:flutter_benchu/utils/commonPkg.dart';
import 'package:flutter/widgets.dart';

mixin LoadingMixin<T extends StatefulWidget> on State<T> {
  bool isLoading = false;

  loadingProvider(Widget child, {Color color = Colors.black54}) {
    return Stack(
      children: <Widget>[
        child,
        if (isLoading)
          Positioned.fill(
            child: Container(
              color: color,
              child: Loading(),
            ),
          ),
      ],
    );
  }

  showLoading(bool show) {
    if (!mounted) {
      return;
    }
    setState(() {
      isLoading = show;
    });
  }
}
